library(data.table)
library(questionr)
library(readstata13)
library(survey)
library(texreg)
library(weights)

# set working directory to location of replication archive
setwd("")

# 2024 September YouGov

yougov <- read.dta13("YouGovOhio.dta")

# recode demographic responses to make consistent with other surveys and for
# use in analyses later

# age
yougov$age <- 2024 - yougov$birthyear1
dim(yougov[which(yougov$age<35),])[1]
dim(yougov[which(yougov$age<35),])[1]/1000
dim(yougov[which(yougov$age>35 & yougov$age<45),])[1]
dim(yougov[which(yougov$age>35 & yougov$age<45),])[1]/1000
dim(yougov[which(yougov$age>45 & yougov$age<65),])[1]
dim(yougov[which(yougov$age>45 & yougov$age<65),])[1]/1000
dim(yougov[which(yougov$age>=65),])[1]
dim(yougov[which(yougov$age>=65),])[1]/1000

# gender
yougov$female <- ifelse(yougov$genderusr1=="Female", 1, 0)
table(yougov$female)
prop.table(table(yougov$female))

# race
yougov$white <- ifelse(yougov$raceuslist=="White", 1, 0)
table(yougov$white)
prop.table(table(yougov$white))

yougov$hispanic <- ifelse(yougov$hispuslist=="Yes", 1, 0)
table(yougov$hispanic)
prop.table(table(yougov$hispanic))

# education
yougov$education <- ifelse(yougov$educlevusr=="No HS", 1, NA)
yougov$education <- ifelse(yougov$educlevusr=="High school graduate", 2, yougov$education)
yougov$education <- ifelse(yougov$educlevusr=="Some college", 3, yougov$education)
yougov$education <- ifelse(yougov$educlevusr=="2-year", 4, yougov$education)
yougov$education <- ifelse(yougov$educlevusr=="4-year", 5, yougov$education)
yougov$education <- ifelse(yougov$educlevusr=="Post-grad", 6, yougov$education)
table(yougov$education)
prop.table(table(yougov$education))

# income
yougov$income <- ifelse(as.numeric(yougov$famincmlev)==17, NA, as.numeric(yougov$famincmlev))
table(yougov$income, useNA = "always")
prop.table(table(yougov$income, useNA = "always"))

# party ID
yougov$dem <- ifelse(yougov$partyidpt3=="Democrat", 1, 0)
yougov$gop <- ifelse(yougov$partyidpt3=="Republican", 1, 0)
yougov$ind <- ifelse(yougov$partyidpt3=="Independent", 1, 0)
table(yougov$partyidpt3)
prop.table(table(yougov$partyidpt3))

# ideology
yougov$ideo <- ifelse(as.numeric(yougov$ideousrlev)<=5, as.numeric(yougov$ideousrlev), NA)
table(yougov$ideo, useNA = "always")
prop.table(table(yougov$ideo, useNA = "always"))

# area of residence
yougov$ruralness <- ifelse(yougov$areatypes1=="City", 1, NA)
yougov$ruralness <- ifelse(yougov$areatypes1=="Suburb", 2, yougov$ruralness)
yougov$ruralness <- ifelse(yougov$areatypes1=="Small-town", 3, yougov$ruralness)
yougov$ruralness <- ifelse(yougov$areatypes1=="Country or rural", 4, yougov$ruralness)
table(yougov$ruralness, useNA = "always")
prop.table(table(yougov$ruralness, useNA = "always"))

# recode responses to prosecutor questions for analysis

# know prosecutor's name?
yougov$prosecutingattorney_correct_DKs <- ifelse(yougov$prosecutingattorney_correct==0 & yougov$prosecutorname_respondent=="__DK__                                                               ", "Don't Know", yougov$prosecutingattorney_correct)

# know prosecutor's party?
# read in data file that contains names and party IDs of all Ohio prosecutors
ohio_prosecutors_pid <- fread("Ohio_prosecutors.csv", header = TRUE, stringsAsFactors = FALSE)
# merge with survey responses
yougov <- merge(yougov, ohio_prosecutors_pid, by = "prosecutingattorney", all.x = TRUE)
# code responses as correct or incorrect given respondent answer and actual PID
yougov$prosecutingattorney_party_correct <- ifelse(yougov$prosecutingattorney_party=="D" & yougov$cprocparty=="Democratic Party", "Correct", NA)
yougov$prosecutingattorney_party_correct <- ifelse(yougov$prosecutingattorney_party=="D" & yougov$cprocparty=="Republican Party", "Incorrect", yougov$prosecutingattorney_party_correct)
yougov$prosecutingattorney_party_correct <- ifelse(yougov$prosecutingattorney_party=="D" & yougov$cprocparty=="I'm not sure", "Don't Know", yougov$prosecutingattorney_party_correct)
yougov$prosecutingattorney_party_correct <- ifelse(yougov$prosecutingattorney_party=="R" & yougov$cprocparty=="Democratic Party", "Incorrect", yougov$prosecutingattorney_party_correct)
yougov$prosecutingattorney_party_correct <- ifelse(yougov$prosecutingattorney_party=="R" & yougov$cprocparty=="Republican Party", "Correct", yougov$prosecutingattorney_party_correct)
yougov$prosecutingattorney_party_correct <- ifelse(yougov$prosecutingattorney_party=="R" & yougov$cprocparty=="I'm not sure", "Don't Know", yougov$prosecutingattorney_party_correct)
yougov$prosecutingattorney_party_correct <- ifelse(yougov$prosecutingattorney_party=="I", NA, yougov$prosecutingattorney_party_correct)
# also create numerical version of correct/incorrect
yougov$prosecutingattorney_party_correct_num <- ifelse(yougov$prosecutingattorney_party_correct=="Correct", 1, 0)
yougov$prosecutingattorney_party_correct_num <- ifelse(yougov$prosecutingattorney_party=="I", NA, yougov$prosecutingattorney_party_correct_num)

# is the respondent a copartisan of the prosecutor?
yougov$prosecutingattorney_copartisan <- ifelse(yougov$prosecutingattorney_party=="D" & yougov$partyidpt3=="Democrat", 1, 0)
yougov$prosecutingattorney_copartisan <- ifelse(yougov$prosecutingattorney_party=="R" & yougov$partyidpt3=="Republican", 1, yougov$prosecutingattorney_copartisan)

# knowledge of prosecutor responsibilities/powers
yougov$know_charging <- ifelse(yougov$finsaychrg=="The prosecutor", 1, 0)
yougov$know_plea <- ifelse(yougov$finsaypldl=="The prosecutor", 1, 0)
yougov$know_scale <- yougov$know_charging + yougov$know_plea

# prosecutor approval
yougov$prosecutingattorney_approval_bin <- ifelse(yougov$cprocapprv=="Strongly approve", 1, NA)
yougov$prosecutingattorney_approval_bin <- ifelse(yougov$cprocapprv=="Somewhat approve", 1, yougov$prosecutingattorney_approval_bin)
yougov$prosecutingattorney_approval_bin <- ifelse(yougov$cprocapprv=="Neither approve nor disapprove", 0, yougov$prosecutingattorney_approval_bin)
yougov$prosecutingattorney_approval_bin <- ifelse(yougov$cprocapprv=="Somewhat disapprove", 0, yougov$prosecutingattorney_approval_bin)
yougov$prosecutingattorney_approval_bin <- ifelse(yougov$cprocapprv=="Strongly disapprove", 0, yougov$prosecutingattorney_approval_bin)
# also as a factor for ordinal regression
yougov$prosecutingattorney_approval_ord <- factor(yougov$cprocapprv, 
                                                  levels = c("Strongly disapprove",
                                                             "Somewhat disapprove",
                                                             "Neither approve nor disapprove",
                                                             "Somewhat approve",
                                                             "Strongly approve"))

################################################################################
################################################################################

# 2024 CES

CES <- fread("CCES24_UTKModule.csv", header = TRUE, stringsAsFactors = FALSE)

# recode demographic responses to make consistent with other surveys and for
# use in analyses later

#age
CES$age <- 2024 - CES$birthyr
dim(CES[which(CES$age<35),])[1]
dim(CES[which(CES$age<35),])[1]/1000
dim(CES[which(CES$age>35 & CES$age<45),])[1]
dim(CES[which(CES$age>35 & CES$age<45),])[1]/1000
dim(CES[which(CES$age>45 & CES$age<65),])[1]
dim(CES[which(CES$age>45 & CES$age<65),])[1]/1000
dim(CES[which(CES$age>=65),])[1]
dim(CES[which(CES$age>=65),])[1]/1000

#gender
CES$female <- ifelse(CES$gender4==2, 1, 0)
table(CES$gender4)
prop.table(table(CES$gender4))

#race
CES$white <- ifelse(CES$race==1, 1, 0)
table(CES$white)
prop.table(table(CES$white))

CES$hispanic <- ifelse(CES$hispanic==1, 1, 0)
table(CES$hispanic)
prop.table(table(CES$hispanic))

#education
CES$education <- CES$educ
table(CES$education)
prop.table(table(CES$education))

#income
CES$income <- ifelse(CES$faminc_new==97, NA, CES$faminc_new)
table(CES$income, useNA = "always")
prop.table(table(CES$income, useNA = "always"))

#party ID
CES$dem <- ifelse(CES$pid3==1, 1, 0)
CES$gop <- ifelse(CES$pid3==2, 1, 0)
CES$ind <- ifelse(CES$pid3==3, 1, 0)
table(CES$pid3)
prop.table(table(CES$pid3))

#ideology
CES$ideo <- ifelse(CES$CC24_330a==8, NA, CES$CC24_330a)
table(CES$ideo, useNA = "always")
prop.table(table(CES$ideo, useNA = "always"))

#area of residence
CES$ruralness <- ifelse(CES$urbancity==5, NA, CES$urbancity)
table(CES$ruralness, useNA = "always")
prop.table(table(CES$ruralness, useNA = "always"))

# recode responses to prosecutor questions for analysis

# knows title of prosecutor
CES$prosecutor_name_correct <- ifelse(CES$UTK340==1 & CES$CLPCalled=="District Attorney", "Correct", NA)
CES$prosecutor_name_correct <- ifelse(CES$UTK340==2 & CES$CLPCalled=="County Attorney", "Correct", CES$prosecutor_name_correct)
CES$prosecutor_name_correct <- ifelse(CES$UTK340==3 & CES$CLPCalled=="County Prosecutor", "Correct", CES$prosecutor_name_correct)
CES$prosecutor_name_correct <- ifelse(CES$UTK340==4 & CES$CLPCalled=="Prosecuting Attorney", "Correct", CES$prosecutor_name_correct)
CES$prosecutor_name_correct <- ifelse(CES$UTK340==5 & CES$CLPCalled=="Commonwealth\xd5s attorney" | CES$UTK340==5 & CES$CLPCalled=="Commonwealth's Attorney", "Correct", CES$prosecutor_name_correct)
CES$prosecutor_name_correct <- ifelse(CES$UTK340==6 & CES$CLPCalled=="State's Attorney" | CES$UTK340==6 & CES$CLPCalled=="State Attorney", "Correct", CES$prosecutor_name_correct)
CES$prosecutor_name_correct <- ifelse(CES$UTK340==7 & CES$CLPCalled=="Solicitor", "Correct", CES$prosecutor_name_correct)
CES$prosecutor_name_correct <- ifelse(CES$UTK340==8 & CES$CLPCalled=="Attorney General", "Correct", CES$prosecutor_name_correct)
CES$prosecutor_name_correct <- ifelse(CES$UTK340==9 & CES$CLPCalled=="US Attorney", "Correct", CES$prosecutor_name_correct)
CES$prosecutor_name_correct <- ifelse(CES$UTK340==10, "Don't Know", CES$prosecutor_name_correct)
CES$prosecutor_name_correct <- ifelse(CES$CLPCalled=="", "Omit", CES$prosecutor_name_correct)
CES$prosecutor_name_correct <- ifelse(CES$UTK340>0 & CES$UTK340<10 & is.na(CES$prosecutor_name_correct), "Incorrect", CES$prosecutor_name_correct)
CES$prosecutor_name_correct <- ifelse(CES$prosecutor_name_correct=="Omit", NA, CES$prosecutor_name_correct)
# binary indicator
CES$prosecutor_name_correct_bin <- ifelse(CES$prosecutor_name_correct=="Correct", 1, CES$prosecutor_name_correct)
CES$prosecutor_name_correct_bin <- ifelse(CES$prosecutor_name_correct=="Incorrect" | CES$prosecutor_name_correct=="Don't Know", 0, CES$prosecutor_name_correct_bin)

# knowledge of prosecutor power/responsibilities
CES$know_charges <- as.numeric(CES$UTK338==3)
CES$know_plea <- as.numeric(CES$UTK339==3)
CES$know_scale <- CES$know_charges + CES$know_plea

# knows whether prosecutor is elected or appointed
CES$CLPElected_correct <- ifelse(CES$UTK341==1 & CES$CLPElected==1, 1, NA)
CES$CLPElected_correct <- ifelse(CES$UTK341==1 & CES$CLPElected==0, 0, CES$CLPElected_correct)
CES$CLPElected_correct <- ifelse(CES$UTK341==2 & CES$CLPElected==0, 1, CES$CLPElected_correct)
CES$CLPElected_correct <- ifelse(CES$UTK341==2 & CES$CLPElected==1, 0, CES$CLPElected_correct)
CES$CLPElected_correct <- ifelse(CES$UTK341==3, "DK", CES$CLPElected_correct)
# separate coding where DKs are incorporated in incorrects
CES$CLPElected_correct_num <- ifelse(CES$CLPElected_correct=="DK", 0, CES$CLPElected_correct)

# knows whether prosecutor was on the ballot
CES$CLPonBallot_correct <- ifelse(CES$UTK428==1 & CES$CLPonBallot==1, 1, NA)
CES$CLPonBallot_correct <- ifelse(CES$UTK428==2 & CES$CLPonBallot==1, 0, CES$CLPonBallot_correct)
CES$CLPonBallot_correct <- ifelse(CES$UTK428==2 & CES$CLPonBallot==0, 1, CES$CLPonBallot_correct)
CES$CLPonBallot_correct <- ifelse(CES$UTK428==1 & CES$CLPonBallot==0, 0, CES$CLPonBallot_correct)
CES$CLPonBallot_correct <- ifelse(CES$UTK428==3, "DK", CES$CLPonBallot_correct)
# separate coding where DKs are incorporated in incorrects
CES$CLPonBallot_correct_num <- ifelse(CES$CLPonBallot_correct=="DK", 0, CES$CLPonBallot_correct)

# how much do they think they know about their prosecutor?
CES$self_knowledge <- ifelse(CES$UTK429<1 | CES$UTK429>5, NA, CES$UTK429)
CES$self_knowledge <- ifelse(CES$UTK429==1, 5, NA)
CES$self_knowledge <- ifelse(CES$UTK429==2, 4, CES$self_knowledge)
CES$self_knowledge <- ifelse(CES$UTK429==3, 3, CES$self_knowledge)
CES$self_knowledge <- ifelse(CES$UTK429==4, 2, CES$self_knowledge)
CES$self_knowledge <- ifelse(CES$UTK429==5, 1, CES$self_knowledge)

################################################################################
################################################################################

# 2024 verasight

verasight2024 <- fread("Verasight2024.csv", header = TRUE, stringsAsFactors = FALSE)
# remove respondents who did not answer our questions about knowledge of
# prosecutors
verasight2024 <- verasight2024[which(verasight2024$educ_pol_5!="" | verasight2024$educ_pol_8!=""),]

# recode demographic responses to make consistent with other surveys and for
# use in analyses later

# age
verasight2024$age <- verasight2024$vs_age

# gender
verasight2024$female <- ifelse(verasight2024$vs_gender=="Female", 1, NA)
verasight2024$female <- ifelse(verasight2024$vs_gender=="Male", 0, verasight2024$female)
verasight2024$female <- ifelse(verasight2024$vs_gender=="Other", 0, verasight2024$female)

# race
verasight2024$white <- ifelse(verasight2024$vs_race=="White", 1, 0)

# education
verasight2024$education <- ifelse(verasight2024$vs_education=="HS or less", 1, NA)
verasight2024$education <- ifelse(verasight2024$vs_education=="Some college/2-yr degree", 2, verasight2024$education)
verasight2024$education <- ifelse(verasight2024$vs_education=="4-yr/post-graduate degree", 3, verasight2024$education)

# income
verasight2024$income <- ifelse(verasight2024$vs_income=="< $50,000", 0, NA)
verasight2024$income <- ifelse(verasight2024$vs_income=="> $50,000", 1, verasight2024$income)

# party ID
verasight2024$dem <- ifelse(verasight2024$vs_pidlean=="Dem/lean Dem", 1, 0)
verasight2024$gop <- ifelse(verasight2024$vs_pidlean=="Rep/lean Rep", 1, 0)
verasight2024$ind <- ifelse(verasight2024$vs_pidlean=="Ind", 1, 0)

# area of residence
verasight2024$metro <- ifelse(verasight2024$vs_metro=="Metropolitan", 1, NA)
verasight2024$metro <- ifelse(verasight2024$vs_metro=="Non-metro", 0, verasight2024$metro)

# knowledge of prosecutor powers/responsibilities
verasight2024$know_charges <- ifelse(verasight2024$educ_pol_5=="The prosecutor", "Correct", NA)
verasight2024$know_charges <- ifelse(verasight2024$educ_pol_5!="The prosecutor" & verasight2024$educ_pol_5!="I don't know" & !is.na(verasight2024$educ_pol_5), "Incorrect", verasight2024$know_charges)
verasight2024$know_charges <- ifelse(verasight2024$educ_pol_5=="I don't know", "DK", verasight2024$know_charges)
verasight2024$know_charges_bin <- verasight2024$educ_pol_5=="The prosecutor"

verasight2024$know_plea <- ifelse(verasight2024$educ_pol_8=="The prosecutor", "Correct", NA)
verasight2024$know_plea <- ifelse(verasight2024$educ_pol_8!="The prosecutor" & verasight2024$educ_pol_8!="I don't know" & !is.na(verasight2024$educ_pol_8), "Incorrect", verasight2024$know_plea)
verasight2024$know_plea <- ifelse(verasight2024$educ_pol_8=="I don't know", "DK", verasight2024$know_plea)
verasight2024$know_plea_bin <- verasight2024$educ_pol_8=="The prosecutor"

verasight2024$know_scale <- verasight2024$know_charges_bin + verasight2024$know_plea_bin

################################################################################
################################################################################

# 2025 verasight

verasight2025 <- fread("Verasight2025.csv", header = TRUE, stringsAsFactors = FALSE)
verasight2025 <- verasight2025[!is.na(verasight2025$policy_21),]

# recode demographic responses to make consistent with other surveys and for
# use in analyses later

#age
verasight2025$age <- verasight2025$vs_age

# gender
verasight2025$female <- ifelse(verasight2025$vs_gender=="Female", 1, NA)
verasight2025$female <- ifelse(verasight2025$vs_gender=="Male", 0, verasight2025$female)
verasight2025$female <- ifelse(verasight2025$vs_gender=="Other", 0, verasight2025$female)

# race
verasight2025$white <- ifelse(verasight2025$vs_race=="White", 1, 0)

verasight2025$hispanic <- ifelse(verasight2025$vs_hispanic=="Yes", 1, 0)

# education
verasight2025$education <- ifelse(verasight2025$vs_education=="Some high school or less", 1, NA)
verasight2025$education <- ifelse(verasight2025$vs_education=="High school graduate or GED", 2, verasight2025$education)
verasight2025$education <- ifelse(verasight2025$vs_education=="Some college, no degree", 3, verasight2025$education)
verasight2025$education <- ifelse(verasight2025$vs_education=="2-year or associate degree", 4, verasight2025$education)
verasight2025$education <- ifelse(verasight2025$vs_education=="4-year or bachelor degree", 5, verasight2025$education)
verasight2025$education <- ifelse(verasight2025$vs_education=="Post-graduate degree", 6, verasight2025$education)

# income
verasight2025$income <- ifelse(verasight2025$vs_income=="Less than $15,000", 1, NA)
verasight2025$income <- ifelse(verasight2025$vs_income=="$15,000 to under $50,000", 2, verasight2025$income)
verasight2025$income <- ifelse(verasight2025$vs_income=="$50,000 to under $75,000", 3, verasight2025$income)
verasight2025$income <- ifelse(verasight2025$vs_income=="$75,000 to under $100,000", 4, verasight2025$income)
verasight2025$income <- ifelse(verasight2025$vs_income=="$100,000 to under $150,000", 5, verasight2025$income)
verasight2025$income <- ifelse(verasight2025$vs_income=="$150,000 to under $200,000", 6, verasight2025$income)
verasight2025$income <- ifelse(verasight2025$vs_income=="More than $200,000", 7, verasight2025$income)

# party ID
verasight2025$dem <- ifelse(verasight2025$vs_pid_lean=="The Democratic Party" | verasight2025$vs_pid_base=="Democrat", 1, 0)
verasight2025$gop <- ifelse(verasight2025$vs_pid_lean=="The Republican Party" | verasight2025$vs_pid_base=="Republican", 1, 0)
verasight2025$ind <- ifelse(verasight2025$vs_pid_lean=="Neither", 1, 0)

# area of residence
verasight2025$metro <- ifelse(verasight2025$vs_metro=="Metropolitan", 1, NA)
verasight2025$metro <- ifelse(verasight2025$vs_metro=="Non-metro", 0, verasight2025$metro)

# how much do they think they know about their prosecutor?
verasight2025$self_knowledge <- verasight2025$policy_21

################################################################################
################################################################################

# Table 3--Role Knowledge Questions

# final say on criminal charges
# YouGov
wtd.table(yougov$finsaychrg=="The prosecutor", weights = yougov$weight)
prop.table(wtd.table(yougov$finsaychrg=="The prosecutor", weights = yougov$weight))
sum(table(yougov$finsaychrg=="The prosecutor"))
# Verasight 2024
wtd.table(verasight2024$know_charges, weights = verasight2024$weight)
prop.table(wtd.table(verasight2024$know_charges, weights = verasight2024$weight))
sum(table(verasight2024$know_charges))
# CES
wtd.table(CES$know_charges, weights = CES$teamweight)
prop.table(wtd.table(CES$know_charges, weights = CES$teamweight))
sum(table(CES$know_charges))

# final say on plea deals
# YouGov
wtd.table(yougov$finsaypldl=="The prosecutor", weights = yougov$weight)
prop.table(wtd.table(yougov$finsaypldl=="The prosecutor", weights = yougov$weight))
sum(table(yougov$finsaypldl=="The prosecutor"))
# Verasight 2024
wtd.table(verasight2024$know_plea, weights = verasight2024$weight)
prop.table(wtd.table(verasight2024$know_plea, weights = verasight2024$weight))
sum(table(verasight2024$know_plea))
# CES
wtd.table(CES$know_plea, weights = CES$teamweight)
prop.table(wtd.table(CES$know_plea, weights = CES$teamweight))
sum(table(CES$know_plea))

# in text we make reference to proportions of certain wrong responses; these tables
# provide the full range of responses rather than coded correct/incorrect

wtd.table(yougov$finsaychrg, weights = yougov$weight)
prop.table(wtd.table(yougov$finsaychrg, weights = yougov$weight))

wtd.table(verasight2024$educ_pol_5, weights = verasight2024$weight)
prop.table(wtd.table(verasight2024$educ_pol_5, weights = verasight2024$weight))

wtd.table(CES$UTK338, weights = CES$teamweight)
prop.table(wtd.table(CES$UTK338, weights = CES$teamweight))


wtd.table(yougov$finsaypldl, weights = yougov$weight)
prop.table(wtd.table(yougov$finsaypldl, weights = yougov$weight))

wtd.table(verasight2024$educ_pol_8, weights = verasight2024$weight)
prop.table(wtd.table(verasight2024$educ_pol_8, weights = verasight2024$weight))

wtd.table(CES$UTK339, weights = CES$teamweight)
prop.table(wtd.table(CES$UTK339, weights = CES$teamweight))

################################################################################
################################################################################

# Table 4--Knowledge of Respondent's Specific Prosecutors

# CES--title of local prosecutor
wtd.table(CES$prosecutor_name_correct, weights=CES$teamweight)
prop.table(wtd.table(CES$prosecutor_name_correct, weights=CES$teamweight))
sum(table(CES$prosecutor_name_correct))

# CES--prosecutor elected/appointed
wtd.table(CES$CLPElected_correct, weights = CES$teamweight)
prop.table(wtd.table(CES$CLPElected_correct, weights = CES$teamweight))
sum(table(CES$CLPElected_correct))

# CES--was prosecutor on ballot?
wtd.table(CES$CLPonBallot_correct, weights = CES$teamweight)
prop.table(wtd.table(CES$CLPonBallot_correct, weights = CES$teamweight))
sum(table(CES$CLPonBallot_correct))

# YouGov--name of local prosecutor
wtd.table(yougov$prosecutingattorney_correct_DKs, weights = yougov$weight)
prop.table(wtd.table(yougov$prosecutingattorney_correct_DKs, weights = yougov$weight))
sum(table(yougov$prosecutingattorney_correct_DKs))

# YouGov--party of local prosecutor
wtd.table(yougov$prosecutingattorney_party_correct, weights = yougov$weight)
prop.table(wtd.table(yougov$prosecutingattorney_party_correct, weights = yougov$weight))
sum(table(yougov$prosecutingattorney_party_correct))

################################################################################
################################################################################

# Table 5--Comparative Knowledge

# CES
wtd.table(CES$self_knowledge, weights = CES$teamweight)
prop.table(wtd.table(CES$self_knowledge, weights = CES$teamweight))

# Verasight
wtd.table(verasight2025$self_knowledge, weights = verasight2025$weight)
prop.table(wtd.table(verasight2025$self_knowledge, weights = verasight2025$weight))

# in-text we note that the proportions of respondents who say they know at least
# as much about their prosecutor as other officials is greater than the
# proportions who say they know less; these t-tests demonstrate the significance
# of these differences
weights::wtd.t.test(CES$self_knowledge>=3, CES$self_knowledge<=2, weight = CES$teamweight)
weights::wtd.t.test(verasight2025$self_knowledge<=3, verasight2025$self_knowledge>=4, weight = verasight2025$weight)

# we also discus in-text the proportions of 2024 CES respondents who could correctly
# name their House member and the PID of their governor:
CES_common <- fread("CCES24_Common_OUTPUT.csv", header = TRUE, stringsAsFactors = FALSE)
# respondents' guesses are 2 if GOP, 3 if Democratic
# state governor
wtd.table(CES_common$CC24_311a, CES_common$CurrentGovParty, weights = CES_common$commonweight)
prop.table(wtd.table(CES_common$CC24_311a, CES_common$CurrentGovParty, weights = CES_common$commonweight))
# US House member
wtd.table(CES_common$CC24_311d, CES_common$CurrentHouseParty, weights = CES_common$commonweight)
prop.table(wtd.table(CES_common$CC24_311d, CES_common$CurrentHouseParty, weights = CES_common$commonweight))

################################################################################
################################################################################

# Table 6--Information Sources

# newspapers
wtd.table(CES$UTK430_1, weights = CES$teamweight)
prop.table(wtd.table(CES$UTK430_1, weights = CES$teamweight))

# online news
wtd.table(CES$UTK430_3, weights = CES$teamweight)
prop.table(wtd.table(CES$UTK430_3, weights = CES$teamweight))

# TV news
wtd.table(CES$UTK430_2, weights = CES$teamweight)
prop.table(wtd.table(CES$UTK430_2, weights = CES$teamweight))

# social media
wtd.table(CES$UTK430_4, weights = CES$teamweight)
prop.table(wtd.table(CES$UTK430_4, weights = CES$teamweight))

# prosecutor's office's website/emails
wtd.table(CES$UTK430_5, weights = CES$teamweight)
prop.table(wtd.table(CES$UTK430_5, weights = CES$teamweight))

# political party
wtd.table(CES$UTK430_6, weights = CES$teamweight)
prop.table(wtd.table(CES$UTK430_6, weights = CES$teamweight))

# prosecutor or associates
wtd.table(CES$UTK430_7, weights = CES$teamweight)
prop.table(wtd.table(CES$UTK430_7, weights = CES$teamweight))

# advocacy groups
wtd.table(CES$UTK430_8, weights = CES$teamweight)
prop.table(wtd.table(CES$UTK430_8, weights = CES$teamweight))

# none of these sources
wtd.table(CES$UTK430_9, weights = CES$teamweight)
prop.table(wtd.table(CES$UTK430_9, weights = CES$teamweight))

################################################################################
################################################################################

# Table 7--Effect of Knowledge on Prosecutor Approval

know_name <- lm(prosecutingattorney_approval_bin ~ prosecutingattorney_correct, yougov, weights = weight)
summary(know_name)

know_name_controls <- lm(prosecutingattorney_approval_bin ~ prosecutingattorney_correct + 
                           age + female + hispanic + white + education + income + 
                           ruralness + dem + gop + ideo, yougov, weights = weight)
summary(know_name_controls)

know_copartisan <- lm(prosecutingattorney_approval_bin ~ prosecutingattorney_copartisan*prosecutingattorney_party_correct_num, yougov, weights = weight)
summary(know_copartisan)

know_copartisan_controls <- lm(prosecutingattorney_approval_bin ~ prosecutingattorney_copartisan*prosecutingattorney_party_correct_num + 
                                 age + female + hispanic + white + education + income + 
                                 ruralness + dem + gop + ideo, yougov, weights = weight)
summary(know_copartisan_controls)

know_scale <- lm(prosecutingattorney_approval_bin ~ know_scale, yougov, weights = weight)
summary(know_scale)

know_scale_controls <- lm(prosecutingattorney_approval_bin ~ know_scale + 
                            age + female + hispanic + white + education + income + 
                            ruralness + dem + gop + ideo, yougov, weights = weight)
summary(know_scale_controls)

know_omnibus <- lm(prosecutingattorney_approval_bin ~ prosecutingattorney_correct + 
                     prosecutingattorney_copartisan*prosecutingattorney_party_correct_num +
                     know_scale, yougov, weights = weight)
summary(know_omnibus)

know_omnibus_controls <- lm(prosecutingattorney_approval_bin ~ prosecutingattorney_correct + 
                              prosecutingattorney_copartisan*prosecutingattorney_party_correct_num +
                              know_scale + 
                              age + female + hispanic + white + education + income + 
                              ruralness + dem + gop + ideo, yougov, weights = weight)
summary(know_omnibus_controls)

texreg(l = list(know_name, know_name_controls, know_copartisan, 
                know_copartisan_controls, know_scale, know_scale_controls,
                know_omnibus, know_omnibus_controls),
       custom.coef.map = list("(Intercept)" = "Intercept",
                              "prosecutingattorney_correct" = "Knows Prosecutor Name?",
                              "prosecutingattorney_copartisan" = "Is a Copartisan of the Prosecutor?",
                              "prosecutingattorney_party_correct_num" = "Knows the Prosecutor's Party?",
                              "prosecutingattorney_copartisan:prosecutingattorney_party_correct_num" = "Is a Copartisan of the Prosecutor? x Knows the Prosecutor's Party?",
                              "know_scale" = "Knowledge Scale (0-2)"),
       stars = 0.05,
       caption = "Effect of Knowledge on Prosecutor Approval",
       caption.above = TRUE)

################################################################################
################################################################################

# Table SI.1--Survey Descriptives

# age
# YouGov Ohio
dim(yougov[which(yougov$age<35),])[1]
dim(yougov[which(yougov$age<35),])[1]/1000
dim(yougov[which(yougov$age>35 & yougov$age<45),])[1]
dim(yougov[which(yougov$age>35 & yougov$age<45),])[1]/1000
dim(yougov[which(yougov$age>45 & yougov$age<65),])[1]
dim(yougov[which(yougov$age>45 & yougov$age<65),])[1]/1000
dim(yougov[which(yougov$age>=65),])[1]
dim(yougov[which(yougov$age>=65),])[1]/1000
# CES
dim(CES[which(CES$age<35),])[1]
dim(CES[which(CES$age<35),])[1]/1000
dim(CES[which(CES$age>35 & CES$age<45),])[1]
dim(CES[which(CES$age>35 & CES$age<45),])[1]/1000
dim(CES[which(CES$age>45 & CES$age<65),])[1]
dim(CES[which(CES$age>45 & CES$age<65),])[1]/1000
dim(CES[which(CES$age>=65),])[1]
dim(CES[which(CES$age>=65),])[1]/1000
# Verasight 2024
dim(verasight2024[which(verasight2024$age<35),])[1]
dim(verasight2024[which(verasight2024$age<35),])[1]/1000
dim(verasight2024[which(verasight2024$age>35 & verasight2024$age<45),])[1]
dim(verasight2024[which(verasight2024$age>35 & verasight2024$age<45),])[1]/1000
dim(verasight2024[which(verasight2024$age>45 & verasight2024$age<65),])[1]
dim(verasight2024[which(verasight2024$age>45 & verasight2024$age<65),])[1]/1000
dim(verasight2024[which(verasight2024$age>=65),])[1]
dim(verasight2024[which(verasight2024$age>=65),])[1]/1000
# Verasight 2025
dim(verasight2025[which(verasight2025$age<35),])[1]
dim(verasight2025[which(verasight2025$age<35),])[1]/1000
dim(verasight2025[which(verasight2025$age>35 & verasight2025$age<45),])[1]
dim(verasight2025[which(verasight2025$age>35 & verasight2025$age<45),])[1]/1000
dim(verasight2025[which(verasight2025$age>45 & verasight2025$age<65),])[1]
dim(verasight2025[which(verasight2025$age>45 & verasight2025$age<65),])[1]/1000
dim(verasight2025[which(verasight2025$age>=65),])[1]
dim(verasight2025[which(verasight2025$age>=65),])[1]/1000

# gender
# YouGov Ohio
table(yougov$female)
prop.table(table(yougov$female))
# CES
table(CES$gender4)
prop.table(table(CES$gender4))
# Verasight 2024
table(verasight2024$vs_gender)
prop.table(table(verasight2024$vs_gender))
# Verasight 2025
table(verasight2025$vs_gender)
prop.table(table(verasight2025$vs_gender))

# race
# YouGov Ohio
yougov$white <- ifelse(yougov$raceuslist=="White", 1, 0)
table(yougov$white)
# CES
table(CES$white)
prop.table(table(CES$white))
# Verasight 2024
table(verasight2024$white)
prop.table(table(verasight2024$white))
# Verasight 2025
table(verasight2025$white)
prop.table(table(verasight2025$white))

# hispanic
# YouGov Ohio
table(yougov$hispanic)
prop.table(table(yougov$hispanic))
# CES
table(CES$hispanic)
prop.table(table(CES$hispanic))
# Verasight 2024
# Verasight 2025
table(verasight2025$hispanic)
prop.table(table(verasight2025$hispanic))

# education
# YouGov Ohio
table(yougov$education)
prop.table(table(yougov$education))
# CES
table(CES$education)
prop.table(table(CES$education))
# Verasight 2024
table(verasight2024$education)
prop.table(table(verasight2024$education))
# Verasight 2025
table(verasight2025$education)
prop.table(table(verasight2025$education))

# income
# YouGov Ohio
table(yougov$income, useNA = "always")
prop.table(table(yougov$income, useNA = "always"))
# CES
table(CES$income, useNA = "always")
prop.table(table(CES$income, useNA = "always"))
# Verasight 2024
table(verasight2024$income, useNA = "always")
prop.table(table(verasight2024$income, useNA = "always"))
# Verasight 2025
table(verasight2025$income, useNA = "always")
prop.table(table(verasight2025$income, useNA = "always"))

# party ID
# YouGov Ohio
table(yougov$partyidpt3)
prop.table(table(yougov$partyidpt3))
# CES
table(CES$pid3)
prop.table(table(CES$pid3))
# Verasight 2024
dim(verasight2024[which(verasight2024$vs_pidlean=="Dem/lean Dem" | verasight2024$vs_pidbase=="Democrat"),])[1]
dim(verasight2024[which(verasight2024$vs_pidlean=="Dem/lean Dem" | verasight2024$vs_pidbase=="Democrat"),])[1]/1000
dim(verasight2024[which(verasight2024$vs_pidlean=="Rep/lean Rep" | verasight2024$vs_pidbase=="Republican"),])[1]
dim(verasight2024[which(verasight2024$vs_pidlean=="Rep/lean Rep" | verasight2024$vs_pidbase=="Republican"),])[1]/1000
dim(verasight2024[which(verasight2024$vs_pidlean=="Ind"),])[1]
dim(verasight2024[which(verasight2024$vs_pidlean=="Ind"),])[1]/1000
# there is one "other" respondent who didn't answer the lean question
# Verasight 2025
dim(verasight2025[which(verasight2025$vs_pid_lean=="The Democratic Party" | verasight2025$vs_pid_base=="Democrat"),])[1]
dim(verasight2025[which(verasight2025$vs_pid_lean=="The Democratic Party" | verasight2025$vs_pid_base=="Democrat"),])[1]/1000
dim(verasight2025[which(verasight2025$vs_pid_lean=="The Republican Party" | verasight2025$vs_pid_base=="Republican"),])[1]
dim(verasight2025[which(verasight2025$vs_pid_lean=="The Republican Party" | verasight2025$vs_pid_base=="Republican"),])[1]/1000
dim(verasight2025[which(verasight2025$vs_pid_base=="Independent" & verasight2025$vs_pid_lean=="Neither"),])[1]
dim(verasight2025[which(verasight2025$vs_pid_base=="Independent" & verasight2025$vs_pid_lean=="Neither"),])[1]/1000
dim(verasight2025[which(verasight2025$vs_pid_base=="Other or none" & verasight2025$vs_pid_lean=="Neither"),])[1]
dim(verasight2025[which(verasight2025$vs_pid_base=="Other or none" & verasight2025$vs_pid_lean=="Neither"),])[1]/1000

# ideology
# YouGov Ohio
table(yougov$ideo, useNA = "always")
prop.table(table(yougov$ideo, useNA = "always"))
# CES
table(CES$ideo, useNA = "always")
prop.table(table(CES$ideo, useNA = "always"))
# Verasight 2024
# Verasight 2025

# area of residence
# YouGov Ohio
table(yougov$ruralness, useNA = "always")
prop.table(table(yougov$ruralness, useNA = "always"))
# CES
table(CES$ruralness, useNA = "always")
prop.table(table(CES$ruralness, useNA = "always"))
# Verasight 2024
table(verasight2024$metro, useNA = "always")
prop.table(table(verasight2024$metro, useNA = "always"))
# Verasight 2025
table(verasight2025$metro, useNA = "always")
prop.table(table(verasight2025$metro, useNA = "always"))

################################################################################
################################################################################

# Table SI.2--YouGov Ohio Knowledge Correlates

prosecutor_name_model_yougov <- lm(prosecutingattorney_correct ~ age + female + hispanic + white +
                              education + income + ruralness + dem + gop + ideo, 
                            data = yougov)
summary(prosecutor_name_model_yougov)

prosecutor_party_model_yougov <- lm(prosecutingattorney_party_correct_num ~ age + female + hispanic + white +
                               education + income + ruralness + dem + gop + ideo, 
                             data = yougov)
summary(prosecutor_party_model_yougov)

know_charging_model_yougov <- lm(know_charging ~ age + female + hispanic + white +
                            education + income + ruralness + dem + gop + ideo, 
                          data = yougov)
summary(know_charging_model_yougov)

know_plea_model_yougov <- lm(know_plea ~ age + female + hispanic + white +
                        education + income + ruralness + dem + gop + ideo, 
                      data = yougov)
summary(know_plea_model_yougov)

know_scale_model_yougov <- lm(know_scale ~ age + female + hispanic + white +
                         education + income + ruralness + dem + gop + ideo, 
                       data = yougov)
summary(know_scale_model_yougov)

texreg(l = list(prosecutor_name_model_yougov, prosecutor_party_model_yougov,
                know_charging_model_yougov, know_plea_model_yougov, know_scale_model_yougov),
       caption = "BGSU Knowledge Correlates",
       custom.model.names = c("Pros. Name", "Pros. Party", "Know. Charge",
                              "Know. Plea", "Know. Scale"),
       custom.coef.names = c("Intercept", "Age", "Female", "Hispanic", "White",
                             "Education", "Income", "Urban-->Rural",
                             "Democrat", "Republican", "Lib.-->Con."),
       caption.above = TRUE,
       stars = 0.05)

################################################################################
################################################################################

# Table SI.3--CES Knowledge Correlates

know_charges_model_ces <- lm(know_charges ~ age + female + hispanic + white +
                           education + income + ruralness + dem + gop + ideo, 
                         data = CES)
summary(know_charges_model_ces)

know_plea_model_ces <- lm(know_plea ~ age + female + hispanic + white +
                        education + income + ruralness + dem + gop + ideo, 
                      data = CES)
summary(know_plea_model_ces)

know_scale_model_ces <- lm(know_scale ~ age + female + hispanic + white +
                         education + income + ruralness + dem + gop + ideo, 
                       data = CES)
summary(know_scale_model_ces)

CLPcalled_model_ces <- lm(prosecutor_name_correct_bin ~ age + female + hispanic + white +
                        education + income + ruralness + dem + gop + ideo, 
                      data = CES)
summary(CLPcalled_model_ces)

CLPElected_correct_model_ces <- lm(CLPElected_correct_num ~ age + female + hispanic + white +
                                 education + income + ruralness + dem + gop + ideo, 
                               data = CES)
summary(CLPElected_correct_model_ces)

CLPElected_correct_model_ces <- lm(CLPElected_correct_num ~ age + female + hispanic + white +
                                 education + income + ruralness + 
                                 dem + gop + ideo, data = CES)
summary(CLPElected_correct_model_ces)

CLPonBallot_correct_model_ces <- lm(CLPonBallot_correct_num ~ age + female + hispanic + white +
                                  education + income + ruralness + 
                                  dem + gop + ideo, data = CES)
summary(CLPonBallot_correct_model_ces)

self_knowledge_model_ces <- lm(self_knowledge ~ age + female + hispanic + white +
                             education + income + ruralness + dem + gop + ideo + 
                             know_charges + know_plea + prosecutor_name_correct_bin +
                             CLPElected_correct_num + CLPonBallot_correct_num, 
                           data = CES)
summary(self_knowledge_model_ces)

texreg(l = list(know_charges_model_ces, know_plea_model_ces, know_scale_model_ces,
                CLPcalled_model_ces, CLPElected_correct_model_ces,
                CLPonBallot_correct_model_ces,
                self_knowledge_model_ces),
       caption = "CES Knowledge Correlates",
       custom.model.names = c("Know. Charge", "Know. Plea", "Know. Scale",
                              "Know CLP Name", "Know CLP Elected", 
                              "Know CLP on Ballot", "Self-Know."),
       custom.coef.names = c("Intercept", "Age", "Female", "Hispanic", "White",
                             "Education", "Income", "Urban-->Rural",
                             "Democrat", "Republican", "Lib.-->Con.",
                             "Know. Charges", "Know. Plea", "Know CLP Name",
                             "Know CLP Elected", "Know CLP on Ballot"),
       caption.above = TRUE,
       stars = 0.05)

################################################################################
################################################################################

# Table SI.4--Verasight 2024 Knowledge Correlates

know_charges_model_verasight2024 <- lm(know_charges_bin ~ age + female + white +
                           education + income + dem + gop + metro, 
                         data = verasight2024)
summary(know_charges_model_verasight2024)

know_plea_model_verasight2024 <- lm(know_plea_bin ~ age + female + white +
                        education + income + dem + gop + metro, 
                      data = verasight2024)
summary(know_plea_model_verasight2024)

know_scale_model_verasight2024 <- lm(know_scale ~ age + female + white +
                         education + income + dem + gop + metro, 
                       data = verasight2024)
summary(know_scale_model_verasight2024)

texreg(l = list(know_charges_model_verasight2024, know_plea_model_verasight2024, know_scale_model_verasight2024),
       caption = "Verasight 2024 Knowledge Correlates",
       custom.model.names = c("Know. Charge", "Know. Plea", "Know. Scale"),
       custom.coef.names = c("Intercept", "Age", "Female", "White", "Education",
                             "Income", "Democrat", "Republican", "Metropolitan"),
       caption.above = TRUE,
       stars = 0.05)

################################################################################
################################################################################

# Table SI.5--Verasight 2025 Knowledge Correlates

self_knowledge_model_verasight2025 <- lm(self_knowledge ~ age + female + white + hispanic +
                             education + income + dem + gop + metro, 
                           data = verasight2025)
summary(self_knowledge_model_verasight2025)

texreg(l = list(self_knowledge_model_verasight2025),
       caption = "Verasight 2025 Knowledge Correlates",
       custom.model.names = c("Self-Know."),
       custom.coef.names = c("Intercept", "Age", "Female", "White", "Hispanic",
                             "Education",
                             "Income", "Democrat", "Republican", "Metropolitan"),
       caption.above = TRUE,
       stars = 0.05)

################################################################################
################################################################################

# Table SI.6--Effect of Knowledge on Prosecutor Approval (Full Models, Linear
# Regression)

texreg(l = list(know_name, know_name_controls, know_copartisan, 
                know_copartisan_controls, know_scale, know_scale_controls,
                know_omnibus, know_omnibus_controls),
       custom.coef.map = list("(Intercept)" = "Intercept",
                              "prosecutingattorney_correct" = "Knows Prosecutor Name?",
                              "prosecutingattorney_copartisan" = "Is a Copartisan of the Prosecutor?",
                              "prosecutingattorney_party_correct_num" = "Knows the Prosecutor's Party?",
                              "prosecutingattorney_copartisan:prosecutingattorney_party_correct_num" = "Is a Copartisan of the Prosecutor? x Knows the Prosecutor's Party?",
                              "know_scale" = "Knowledge Scale (0-2)",
                              "age" = "Age",
                              "female" = "Female",
                              "hispanic" = "Hispanic",
                              "white" = "White",
                              "education" = "Education",
                              "income" = "Income",
                              "ruralness" = "Urban-->Rural",
                              "dem" = "Democrat",
                              "gop" = "Republican",
                              "ideo" = "Lib.-->Con."),
       stars = 0.05,
       caption = "Effect of Knowledge on Prosecutor Approval (Full Models)",
       caption.above = TRUE)

################################################################################
################################################################################

# Table SI.7--Effect of Knowledge on Prosecutor Approval (Full Models, Logistic
# Regression)

yougov_design <- svydesign(id = ~1, weights = ~weight, data = yougov)

know_name_logit <- svyglm(prosecutingattorney_approval_bin ~ prosecutingattorney_correct, yougov_design, family = binomial(link= logit))
summary(know_name_logit)

know_name_controls_logit <- svyglm(prosecutingattorney_approval_bin ~ prosecutingattorney_correct + 
                                     age + female + hispanic + white + education + income + 
                                     ruralness + dem + gop + ideo, yougov_design, family = binomial(link= logit))
summary(know_name_controls_logit)

know_copartisan_logit <- svyglm(prosecutingattorney_approval_bin ~ prosecutingattorney_copartisan*prosecutingattorney_party_correct_num, yougov_design, family = binomial(link= logit))
summary(know_copartisan_logit)

know_copartisan_controls_logit <- svyglm(prosecutingattorney_approval_bin ~ prosecutingattorney_copartisan*prosecutingattorney_party_correct_num + 
                                           age + female + hispanic + white + education + income + 
                                           ruralness + dem + gop + ideo, yougov_design, family = binomial(link= logit))
summary(know_copartisan_controls_logit)

know_scale_logit <- svyglm(prosecutingattorney_approval_bin ~ know_scale, yougov_design, family = binomial(link= logit))
summary(know_scale_logit)

know_scale_controls_logit <- svyglm(prosecutingattorney_approval_bin ~ know_scale + 
                                      age + female + hispanic + white + education + income + 
                                      ruralness + dem + gop + ideo, yougov_design, family = binomial(link= logit))
summary(know_scale_controls_logit)

know_omnibus_logit <- svyglm(prosecutingattorney_approval_bin ~ prosecutingattorney_correct + 
                               prosecutingattorney_copartisan*prosecutingattorney_party_correct_num +
                               know_scale, yougov_design, family = binomial(link= logit))
summary(know_omnibus_logit)

know_omnibus_controls_logit <- svyglm(prosecutingattorney_approval_bin ~ prosecutingattorney_correct + 
                                        prosecutingattorney_copartisan*prosecutingattorney_party_correct_num +
                                        know_scale + 
                                        age + female + hispanic + white + education + income + 
                                        ruralness + dem + gop + ideo, yougov_design, family = binomial(link= logit))
summary(know_omnibus_controls_logit)

texreg(l = list(know_name_logit, know_name_controls_logit, know_copartisan_logit, 
                know_copartisan_controls_logit, know_scale_logit, know_scale_controls_logit,
                know_omnibus_logit, know_omnibus_controls_logit),
       custom.coef.map = list("(Intercept)" = "Intercept",
                              "prosecutingattorney_correct" = "Knows Prosecutor Name?",
                              "prosecutingattorney_copartisan" = "Is a Copartisan of the Prosecutor?",
                              "prosecutingattorney_party_correct_num" = "Knows the Prosecutor's Party?",
                              "prosecutingattorney_copartisan:prosecutingattorney_party_correct_num" = "Is a Copartisan of the Prosecutor? x Knows the Prosecutor's Party?",
                              "know_scale" = "Knowledge Scale (0-2)",
                              "age" = "Age",
                              "female" = "Female",
                              "hispanic" = "Hispanic",
                              "white" = "White",
                              "education" = "Education",
                              "income" = "Income",
                              "ruralness" = "Urban-->Rural",
                              "dem" = "Democrat",
                              "gop" = "Republican",
                              "ideo" = "Lib.-->Con."),
       stars = 0.05,
       include.dispersion = FALSE,
       include.deviance = FALSE,
       include.loglik = TRUE,
       caption = "Effect of Knowledge on Prosecutor Approval (Logistic Regression)",
       caption.above = TRUE)

################################################################################
################################################################################

# Table SI.8--Effect of Knowledge on Prosecutor Approval (Full Models, Ordinal 
# Logistic Regression)

know_name_ordlogit <- svyolr(prosecutingattorney_approval_ord ~ prosecutingattorney_correct, yougov_design)
summary(know_name_ordlogit)
know_name_ordlogit$deviance

know_name_controls_ordlogit <- svyolr(prosecutingattorney_approval_ord ~ prosecutingattorney_correct + 
                                        age + female + hispanic + white + education + income + 
                                        ruralness + dem + gop + ideo, yougov_design)
summary(know_name_controls_ordlogit)
know_name_controls_ordlogit$deviance

know_copartisan_ordlogit <- svyolr(prosecutingattorney_approval_ord ~ prosecutingattorney_copartisan*prosecutingattorney_party_correct_num, yougov_design)
summary(know_copartisan_ordlogit)
know_copartisan_ordlogit$deviance

know_copartisan_controls_ordlogit <- svyolr(prosecutingattorney_approval_ord ~ prosecutingattorney_copartisan*prosecutingattorney_party_correct_num + 
                                              age + female + hispanic + white + education + income + 
                                              ruralness + dem + gop + ideo, yougov_design)
summary(know_copartisan_controls_ordlogit)
know_copartisan_controls_ordlogit$deviance

know_scale_ordlogit <- svyolr(prosecutingattorney_approval_ord ~ know_scale, yougov_design)
summary(know_scale_ordlogit)
know_scale_ordlogit$deviance

know_scale_controls_ordlogit <- svyolr(prosecutingattorney_approval_ord ~ know_scale + 
                                         age + female + hispanic + white + education + income + 
                                         ruralness + dem + gop + ideo, yougov_design)
summary(know_scale_controls_ordlogit)
know_scale_controls_ordlogit$deviance

know_omnibus_ordlogit <- svyolr(prosecutingattorney_approval_ord ~ prosecutingattorney_correct + 
                                  prosecutingattorney_copartisan*prosecutingattorney_party_correct_num +
                                  know_scale, yougov_design)
summary(know_omnibus_ordlogit)
know_omnibus_ordlogit$deviance

know_omnibus_controls_ordlogit <- svyolr(prosecutingattorney_approval_ord ~ prosecutingattorney_correct + 
                                           prosecutingattorney_copartisan*prosecutingattorney_party_correct_num +
                                           know_scale + 
                                           age + female + hispanic + white + education + income + 
                                           ruralness + dem + gop + ideo, yougov_design)
summary(know_omnibus_controls_ordlogit)
know_omnibus_controls_ordlogit$deviance
